﻿<!DOCTYPE html>
<html lang="zh_CN">

<head>
    <title>图像2</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="图形系统开发实战:进阶篇 示例">
    <meta name="author" content="hjq">
    <meta name="keywords" content="canvas,anygraph,javascript">
    <!-- frame所需脚本和样式 -->
    <link rel="stylesheet" href="../../script/bootstrap-3.3.5/css/bootstrap.min.css">   
    <link rel="stylesheet" href="../../script/codemirror/codemirror.css">
    <script src="../../script/lib/jquery-1.11.2.min.js"></script>
    <script src="../../script/codemirror/codemirror_merge.js"></script>
    <!-- 加载代码块 -->
    <link rel="stylesheet" href="../css/styles.css">
    <script src="../js/data_box.js"></script>
    <script src="../js/helper.js"></script>
    <script>
        var pageTitle = "AnyGraph图像类型";
        var pageDesc = "显示AnyGraph图像类型";
    </script>

</head>

<body style="margin:10px;">
    <div id="graphWrapper" data-type="graph" style="width:700px; height:400px; border:solid 1px #CCC;"></div>
    <h3>Data</h3>
    <div id="divData" style="height: 160px;"></div>
</body>

<script>
    let graph;
</script>
<script type="module">
    import { Graph, Image, BgUtil } from "../../src/index.js";

    // graph对象
    graph = new Graph({
        "target": "graphWrapper",
        "enabledGeomEvent": true
    });

    // 新建图层
    let layer = graph.addLayer();
    BgUtil.generateGrid(Object.assign({ "interval": 10, "graph":graph }, graph.getSize()));

    // 绘制图像
    layer.getSource().add(new Image({ "x": 50, "y": 50, "src": "./images/square2.png" }));
    
    // 缩小的图像
    layer.getSource().add(new Image({ "x": 50, "y": 250, "src": "./images/square2.png", "width": 100, "height": 100 }));
    
    // 拉伸变形的图像
    layer.getSource().add(new Image({ "x": 200, "y": 250, "src": "./images/square2.png", "width": 100, "height": 50 }));

    // 放大的图像
    layer.getSource().add(new Image({ "x": 350, "y": 50, "src": "./images/square2.png", "width": 300, "height": 300 }));

    graph.render();
    
    // 为geom绑定click事件
    let geoms = layer.getSource().getData();
    geoms.forEach( geom => {
		geom.on("click", activeShape);
	})
</script>

</html>